package com.ww.springboot.boot.java8.completablefuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * 描述：组合 completableFuture and
 *
 * @author 🧑 ‍wanwei
 * @since 2022-01-20 15:21
 */
public class CompletableFutureDemo4 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> first = CompletableFuture.completedFuture("第一个异步任务");
        CompletableFuture<String> future = CompletableFuture
                //第二个异步任务
                .supplyAsync(() -> "第二个异步任务")
                .thenCombineAsync(first, (s, w) -> {
                    System.out.println(w);
                    System.out.println(s);
                    return "两个异步任务的组合";
                });
        CompletableFuture<String> future2 = CompletableFuture
                //第二个异步任务
                .supplyAsync(() -> "第三个异步任务")
                // (w, s) -> System.out.println(s) 是第三个任务
                .thenCombineAsync(future, (s, w) -> {
                    System.out.println(w);
                    System.out.println(s);
                    return "三个异步任务的组合";
                });
    }
}
